<?php
/**
 * Created by Wang.
 * User: nango
 * Date: 2016-06-02
 * Time: 16:22
 */
namespace Wang\Core;


use Addons\smarty\Swang;

class Controller
{
    /**
     * @var 视图实例对象
     */
    protected $smarty;

    /**
     * @var 数据库实例对象
     */
    protected $db;

    function __construct()

    {
        $this->smarty = new Swang();
    }

    /**
     * 赋值
     * @param $name
     * @param $value
     *
     */
    protected function assign($tpl_var, $value = null, $nocache = false){
        $this->smarty->assign($tpl_var, $value, $nocache);
    }

    /**
     * 输出模板
     * @param null $template
     * @param null $cache_id
     * @param null $compile_id
     * @param null $parent
     *
     */
    protected function display($template = null, $cache_id = null, $compile_id = null, $parent = null){
        if(is_null($template)){
            $oper = parseUrlToArr(2);
            $template = strtolower($oper).'.tpl';
        }

        $this->smarty->display($template, $cache_id, $compile_id, $parent);
    }

    /**
     * 设置模板路径
     * @param $template_dir
     * @param bool|false $isConfig
     *
     */
    protected function setTemplateDir($template_dir, $isConfig = false){
        $this->smarty->setTemplateDir($template_dir, $isConfig);
    }

    public function error($message){
        $this->assign('message',$message);
        $this->display('/Public/Wang/error.tpl');
    }
    /**
     * @param $name
     * @param $arguments
     *
     */
    public function __call($name, $arguments)
    {
        echo '<h1 align="center">您调用的方法'.$name.'不存在!  ):</h1>';
    }

}